var e = getApp(),
	n = require("../../utils/core.js");
Page({
	data: {
		DisplayStatus:true,
		shop_logo: "",
		shop_name: "",
		
	},
	onLoad: function(e) {
		var o = this;
		n.get("wxAppSetting", {}, function(e) {
			var n = e.sysset;
			o.setData({
				shop_logo: n.shoplogo,
				shop_name: n.shopname
			})
		})
	},
	
	onReady: function() {},
	onShow: function() {},
	onHide: function() {},
	onUnload: function() {},
	onPullDownRefresh: function() {},
	onReachBottom: function() {},
	onShareAppMessage: function() {},
	
	bindGetUserInfo: function(o) {
		wx.showLoading({
			title: "加载中",
			
		}),
		wx.getUserProfile({
			desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
			success: (o) => { 
					wx.showLoading({
							title: "加载中"
					}), wx.login({
							success: function(t) {
									n.post("wxapp/login", {
											code: t.code
									}, function(t) {  
											console.log(t);
											console.log(o);
											
											t.error ? n.alert("获取用户登录态失败:" + t.message) : n.get("wxapp/auth", {
													data: o.encryptedData,
													iv: o.iv,
													sessionKey: t.session_key,
													newopenId:t.openid
											}, function(n) { 
													console.log(n);
													1 == n.isblack && wx.showModal({
															title: "无法访问",
															content: "您在商城的黑名单中，无权访问！",
															success: function(n) { 
																	n.confirm && e.close(), n.cancel && e.close();
															}
													}),
													 o.userInfo.openid = t.openid, o.userInfo.id = n.id, o.userInfo.uniacid = n.uniacid, 
													e.setCache("userinfo", o.userInfo), e.setCache("userinfo_openid", o.userInfo.openid), 
													e.setCache("userinfo_id", n.id), e.getSet(), wx.navigateBack({
															changed: !0
													});
											});
									});
							},
							fail: function() {
									n.alert("获取用户信息失败!");
							},
							complete: function() {
									wx.hideLoading();
							}
					});
			}
		})



































		//  wx.login({
		// 	success: function(t) {
				
		// 		n.post("wxapp/login", {
		// 			code: t.code,
					
		// 		},
			
		// 		 function(t) {
		// 			t.error ? n.alert("获取用户登录态失败:" + t.message) : n.get("wxapp/auth", {
		// 				data: o.detail.encryptedData,
		// 				iv: o.detail.iv,
		// 				sessionKey: t.session_key,
						
		// 			}, function(n) {
		// 				1 == n.isblack && wx.showModal({
		// 						title: "无法访问",
		// 						content: "您在商城的黑名单中，无权访问！",
		// 						success: function(n) {
		// 							n.confirm && e.close(), n.cancel &&
		// 								e.close()
										
		// 						}
		// 					}), o.detail.userInfo.openid = n.openId, o.detail
		// 					.userInfo.id = n.id, o.detail.userInfo.uniacid = n
		// 					.uniacid, e.setCache("userinfo", o.detail.userInfo),
		// 					e.setCache("userinfo_openid", o.detail.userInfo
		// 						.openid), e.setCache("userinfo_id", n.id), e
		// 					.getSet()
							
		// 			})
		// 		})
		// 	},
		// 	fail: function() {
		// 		n.alert("获取用户信息失败!")
		// 	},
		// 	complete: function() {
		// 		wx.hideLoading()
		// 	},
			
		// });
		this.setData({
		    DisplayStatus:!this.data.DisplayStatus
		  });
	},

	//通过绑定手机号登录
	getPhoneNumber: function (e) {
		  	console.log(e);
	   var ivObj = e.detail.iv
	   var telObj = e.detail.encryptedData
	   var codeObj = "";
	   var that = this;
	   this.setData({
	       DisplayStatus: true  
	   });
	   //------执行Login---------
	   wx.login({
	    success: res => {
	     console.log('code转换', res.code);
	　　　　　　//用code传给服务器调换session_key
	     wx.request({
	      url: 'https://mall.ccbhzz.com/app/ewei_shopv2_api.php?i=2&r=index.wxsession_key', //接口地址
	      data: {
	       appid: "wxce970427d3c8af78",
	       secret: "1b16bf5251901db8e7fea732ca6a469f",
	       code: res.code,
	       encryptedData: telObj,
	       iv: ivObj
	      },
	      success: function (res) {
	       phoneObj = res.data.phoneNumber;
	       console.log(phoneObj);
		   wx.request({
			   url:'https://mall.ccbhzz.com/app/ewei_shopv2_api.php?i=2&r=index.wxphone',
			   data:{
				   wzphone:res.data.phoneNumber,
			   },
			   method:'POST',
			   success:function(data){
			   	console.log(data)
			   }
		   })
	       wx.setStorage({  //存储数据并准备发送给下一页使用
	        key: "phoneObj",
	        data: res.data.phoneNumber,
			
	       })
	      }
	     })
	 
	     //-----------------是否授权，授权通过进入主页面，授权拒绝则停留在登陆界面
	     if (e.detail.errMsg == 'getPhoneNumber:user deny') { //用户点击拒绝
	      wx.navigateTo({
	       url: '../index/index',
	      })
	     } else { //允许授权执行跳转
	      // wx.navigateTo({
	      //  url: '../test/test',
	      // })
		  wx.navigateBack({
		  	changed: !0
		  });
	     }
	    }
	   });
	
	
	},
	
	navigateBack: function() {
		wx.navigateBack({
			changed: !0
		})
	},
	close: function() {
		wx.navigateBack({
			delta: 0
		})
	}
});
